package forum.communication;

import forum.server.controller.ForumFacadeInt;
import forum.server.exceptions.*;

public class DemoteModeratorMessage extends ClientMessage {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8577884238126137025L;

	private String[] usernames;
	
	public DemoteModeratorMessage(String[] usernames) {
		this.usernames = usernames;
	}
	
	@Override
	public ServerResponse doOperation(ForumFacadeInt forum) {
		try {
			forum.demoteModerator(usernames);
			return new ServerResponse("Successfully demoted the user from Moderator privlidges", true);
		} catch (NotLoggedInException e) {
			return new ServerResponse("Guests cannot demote other users from moderators. Please login.", false);
		} catch (UnauthorizedOpException e) {
			return new ServerResponse(e.getMessage(),false);
		} catch (NoSuchUserException e) {
			return new ServerResponse(e.getMessage(),false);
		} catch (DatabaseException e) {
			return new ServerResponse("The server is currently down for maintanance.\nPlease try again later.",false);
		}
	}
}
